﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        //登录
        private void button1_Click(object sender, EventArgs e)
        {
            string userid = this.textBox1.Text;
            string password = this.textBox2.Text;
            if (userid.Equals("") || password.Equals(""))
            {
                MessageBox.Show("用户名或密码不能为空");
            }
            else
            {
                string connectionString = "server=.;database=Blogs;Uid=sa;pwd=123456";
                SqlConnection SqlCon = new SqlConnection(connectionString);
                SqlCon.Open();
                string sql = "select * from Users where username='" + userid + "' and password='" + password + "'";
                SqlCommand cmd = new SqlCommand(sql, SqlCon);
                cmd.CommandType = CommandType.Text;
                SqlDataReader sdr;
                sdr = cmd.ExecuteReader();
                if (sdr.Read())
                {
                    MessageBox.Show("登录成功", "提示");
                    Mainform main = new Mainform();
                    this.Hide();
                    main.Show();
                }
                else
                {
                    MessageBox.Show("用户名或密码错误", "提示");
                    return;
                }
            }
        }


        //注册
        private void button2_Click(object sender, EventArgs e)
        {

            Form2 form2 = new Form2();
            form2.Show();
        }
    }
}
